package com.eastedu.controller;

import com.eastedu.domain.ObjectValueModel;
import com.eastedu.model.RequestParameter;
import com.eastedu.superise.handler.question.*;
import com.eastedu.superise.handler.question.callback.ChoiceQuestionAnswerParenthesesRollbackHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * The type Question data update controller.
 *
 * @author 袁松明
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/api/v1/question/data-update")
public class QuestionDataUpdateController {

    private final QuestionInsertKnowledgeHistoricalDataHandler insertKnowledgeHandler;
    private final QuestionDeleteKnowledgeHistoricalDataHandler deleteKnowledgeHandler;
    private final QuestionUpdateKnowledgeHistoricalDataHandler updateKnowledgeHandler;
    private final SimilarQuestionHistoricalDataHandler similarQuestionHistoricalDataHandler;
    private final ChoiceQuestionAnswerParenthesesHistoricalDataHandler choiceQuestionAnswerParenthesesHistoricalDataHandler;
    private final ChoiceQuestionAnswerParenthesesHistoricalDataHandler2 ChoiceQuestionAnswerParenthesesHistoricalDataHandler2;
    private final ChoiceQuestionAnswerParenthesesRollbackHandler choiceQuestionAnswerParenthesesRollbackHandler;
    private final FontSizeHistoricalDataHandler fontSizeHistoricalDataHandler;
    private final CompletionHistoricalDataHandler completionHistoricalDataHandler;


    /**
     * 填充知识点
     * 将没有知识点的试题刷上知识点
     *
     * @param parameter 请求参数
     * @return 结果 http entity
     */
    @PostMapping("/insert_knowledge")
    public HttpEntity<ObjectValueModel<Boolean>> insertKnowledge(RequestParameter parameter) {
        insertKnowledgeHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 删除非末级知识点
     *
     * @param parameter 请求参数
     * @return 结果 http entity
     */
    @PostMapping("/delete_knowledge")
    public HttpEntity<ObjectValueModel<Boolean>> deleteKnowledge(RequestParameter parameter) {
        deleteKnowledgeHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 更新知识点
     * 知识点名称和层级变动后处理
     *
     * @param parameter 请求参数
     * @return 结果 http entity
     */
    @PostMapping("/update_knowledge")
    public HttpEntity<ObjectValueModel<Boolean>> updateKnowledge(RequestParameter parameter) {
        updateKnowledgeHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 相识题匹配
     *
     * @param parameter RequestParameter
     * @return Boolean http entity
     */
    @PostMapping("/similarity")
    public HttpEntity<ObjectValueModel<Boolean>> similarityMatch(RequestParameter parameter) {
        similarQuestionHistoricalDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 选择题作答括号
     *
     * @param parameter the parameter
     * @return the http entity
     */
    @PostMapping("/choice-question-answer-parentheses")
    public HttpEntity<ObjectValueModel<Boolean>> choiceQuestionAnswerParenthesesHandler(RequestParameter parameter) {
        choiceQuestionAnswerParenthesesHistoricalDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * Choice question answer parentheses handler 2 http entity.
     *
     * @param parameter the parameter
     * @return the http entity
     */
    @PostMapping("/choice-question-answer-parentheses/underline")
    public HttpEntity<ObjectValueModel<Boolean>> choiceQuestionAnswerParenthesesHandler2(RequestParameter parameter) {
        ChoiceQuestionAnswerParenthesesHistoricalDataHandler2.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }


    /**
     * Choice question answer parentheses rollback http entity.
     *
     * @param parameter the parameter
     * @return the http entity
     */
    @PostMapping("/choice-question-answer-parentheses/rollback")
    @Transactional(rollbackFor = Exception.class)
    public HttpEntity<ObjectValueModel<Boolean>> choiceQuestionAnswerParenthesesRollback(RequestParameter parameter) {
        choiceQuestionAnswerParenthesesRollbackHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * Choice question answer parentheses handler 2 http entity.
     *
     * @param parameter the parameter
     * @return the http entity
     */
    @PostMapping("/completion:transform")
    public HttpEntity<ObjectValueModel<Boolean>> CompletionHistoricalDataHandler(RequestParameter parameter) {
        completionHistoricalDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 移除试题字体大小
     *
     * @param parameter the parameter
     * @return {@return the http entity}
     */
    @PostMapping("/font_size")
    public HttpEntity<ObjectValueModel<Boolean>> fontSize(@RequestBody com.eastedu.data.RequestParameter parameter) {
        fontSizeHistoricalDataHandler.start(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 移除试题字体大小
     *
     * @param taskId the task id
     * @return {@return the http entity}
     */
    @DeleteMapping("/font_size")
    public HttpEntity<ObjectValueModel<Boolean>> fontSizeStop(@RequestParam String taskId) {
        fontSizeHistoricalDataHandler.stop(taskId);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

}
